namespace Radar
{
    using System;
    using System.Collections.Generic;

    internal sealed class IocConfiguration : IIocConfiguration, IConfigurationProvider
    {
        private readonly IDictionary<string, Func<object>> parameterBuilders = new Dictionary<string, Func<object>>();
        private readonly IContainer container;

        private Lifetime lifetime = Lifetime.Transient;

        internal IocConfiguration(IContainer container)
        {
            if (container == null) throw new ArgumentNullException("container");

            this.container = container;
        }

        public Lifetime Lifetime { get { return lifetime; } }
        public IDictionary<string, Func<object>> Parameters { get { return parameterBuilders; } }

        public IIocConfiguration WithDependency(string parameter, string key)
        {
            if (string.IsNullOrEmpty(parameter)) throw new ArgumentNullException("parameter");
            if (string.IsNullOrEmpty(key)) throw new ArgumentNullException("key");

            parameterBuilders[parameter] = () => container.Resolve(key);

            return this;
        }

        public IIocConfiguration WithValue(string parameter, object value)
        {
            if (string.IsNullOrEmpty(parameter)) throw new ArgumentNullException("parameter");

            parameterBuilders[parameter] = () => value;

            return this;
        }

        public IIocConfiguration WithLifetime(Lifetime l)
        {
            if (l == null) throw new ArgumentNullException("l");

            lifetime = l;

            return this;
        }
    }
}